package com.hy.controller;

import com.hy.domain.Section;
import com.hy.domain.dto.R;
import com.hy.service.SectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/section")
public class SectionController {
    @Autowired
    private SectionService sectionService;

    @PostMapping
    public R add(Section section) {
        return sectionService.add(section);
    }

    @GetMapping
    public R list() {
        final List<Section> list = sectionService.list();

        return R.ok(list);
    }

    @DeleteMapping("/{id}")
    public R deleteById(@PathVariable int id) {
        return sectionService.deleteById(id);
    }

    @PutMapping()
    public R update(Section section) {
        final boolean success = sectionService.updateById(section);
        if (success) {
            return R.ok("修改成功！");
        } else {
            return R.fail("修改失败！");
        }
    }
}
